import AV from '../database/index'

export default {
    getNavTags: function() {
        return new Promise(function(resolve, reject) {
            var query = new AV.Query('Navigation');
            query.find().then(function(data) {
                resolve(data)
            }, function(error) {
                reject(error)
            });
        })
    },
    getNavByTagId: function(tagId) {
        tagId = parseInt(tagId)
        return new Promise(function(resolve, reject) {
            var query = new AV.Query('Navigation');
            query.equalTo('cat_id', tagId);
            query.find().then(function(res) {
                resolve(res)
            }, function(error) {
                reject(error)
            })

        })
    },
    login: function(username, password) {
        return new Promise(function(resolve, reject) {
            AV.User.logIn(username, password).then(function(loginedUser) {
                resolve(loginedUser)
            }, function(error) {
                reject(error)
            });
        })
    },
    submitNav: function(data) {
        return new Promise(function(resolve, reject) {
            var navigation = AV.Object.extend('Navigation');
            var navigation = new navigation();
            navigation.set('nav_title', data.title);
            navigation.set('category', data.cat);
            navigation.set('cat_id', data.catId);
            navigation.set('nav_title_img', data.img);
            navigation.set('nav_link', data.link);
            navigation.set('nav_content', data.content);
            navigation.save().then(function(res) {
                resolve(res)
            }, function(error) {
                reject(error)
            });
        })

    }


}